package com.admin.business.portalWebsite.venusSysModelUser;

import com.tiangong.framework.annotation.OpenApi;
import com.tiangong.framework.bo.CDO;
import com.tiangong.framework.bo.Return;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;

/**
 * @description: 范本下载表
 * @create: 2023-11-18 16:45:42
 **/
@Service("venusSysModelUserService")
@Slf4j
public class VenusSysModelUserService{

    @Resource
    VenusSysModelUserDao venusSysModelUserDao;

    /**
     * 添加范本下载表,获取id数据
     *
     * @param cdoRequest - id:
     *                   - user_id:用户id
     *                   - model_id:范本id
     *                   - model_cost:花销
     *                   - operator:退还人
     *                   - restitution:下载状态 0 正常 1已退还
     *                   - restitution_time:返还时间
     *                   - update_time:更新时间
     *                   - begin_time:开始时间
     *                   - state:是否删除：0、正常，1、已删除；
     * @return
     * @author wdf
     * @create: 2023-11-18 16:45:42
     */
    @OpenApi
    public Return addVenusSysModelUser(CDO cdoRequest) {
        venusSysModelUserDao.addVenusSysModelUser(cdoRequest);
        CDO cdoResult = new CDO();
        if (cdoRequest.containsKey("id")) {
            cdoResult.set("id", cdoRequest.get("id"));
        }
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据id，更新范本下载表数据
     *
     * @param cdoRequest - id:
     *                   - user_id:用户id
     *                   - model_id:范本id
     *                   - model_cost:花销
     *                   - operator:退还人
     *                   - restitution:下载状态 0 正常 1已退还
     *                   - restitution_time:返还时间
     *                   - update_time:更新时间
     *                   - begin_time:开始时间
     *                   - state:是否删除：0、正常，1、已删除；
     * @return
     * @author wdf
     * @create: 2023-11-18 16:45:42
     */
    @OpenApi
    public Return updateVenusSysModelUserById(CDO cdoRequest) {
        venusSysModelUserDao.updateVenusSysModelUserById(cdoRequest);
        return Return.SUCCESS;
    }

    /**
     * 根据id，删除范本下载表数据
     *
     * @param cdoRequest - id:
     * @return
     * @author wdf
     * @create: 2023-11-18 16:45:42
     */
    @OpenApi
    public Return deleteVenusSysModelUserById(CDO cdoRequest){
        int count = venusSysModelUserDao.deleteVenusSysModelUserById(cdoRequest.getString("id"));
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据条件，删除范本下载表数据
     *
     * @param cdoRequest
     * @return
     * @author wdf
     * @create: 2023-11-18 16:45:42
     */
    @OpenApi
    public Return deleteVenusSysModelUser(CDO cdoRequest) {
        int count = venusSysModelUserDao.deleteVenusSysModelUser(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据ID，获取范本下载表数据
     *
     * @param cdoRequest - id:
     * @return
     * @author wdf
     * @create: 2023-11-18 16:45:42
     */
    @OpenApi
    public Return getVenusSysModelUserById(CDO cdoRequest) {
        CDO cdoMapperResult = venusSysModelUserDao.getVenusSysModelUserById(cdoRequest.getString("id"));
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据非空条件，获取范本下载表数据列表
     *
     * @param cdoRequest
     * @return
     * @author wdf
     * @create: 2023-11-18 16:45:42
     */
    @OpenApi
    public Return getVenusSysModelUserListPage(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusSysModelUserDao.getVenusSysModelUserListPage(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusSysModelUserDao.getVenusSysModelUserCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
    /**
     * 根据混合条件，获取范本下载表数据列表
     *
     * @param cdoRequest - id:
     * @return
     * @author wdf
     * @create: 2023-11-18 16:45:42
     */
    @OpenApi
    public Return getVenusSysModelUserListPageByCondition(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusSysModelUserDao.getVenusSysModelUserListPageByCondition(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusSysModelUserDao.getVenusSysModelUserCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
}
